﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Control_ItemSize : MonoBehaviour
{
    public Vector2 anchorsPositon= new Vector2(0,0);
    public Transform anvhorsPositonP;

    public float distance = 150;
    public float sizePersent = 1.5f;

    private Vector2 initialSize;
    private Vector2 wordPositon;

    private void Start()
    {
        initialSize = transform.GetComponent<RectTransform>().sizeDelta;
        wordPositon = anvhorsPositonP.TransformPoint(anchorsPositon);
    }
    void Update()
    {
        float y = transform.position.y;

        float persent = Math.Max(0, 1 - (Math.Abs(y - wordPositon.y) / distance));
        //Debug.Log(persent);

        Vector2 size = initialSize + initialSize * (sizePersent - 1) * persent;
        transform.GetComponent<RectTransform>().sizeDelta = size;
    }
}
